/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Test;

import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author myguel
 */
public class ModeloTablaConsultaMaterial extends AbstractTableModel {

    private static final long serialVersionUID = -5453866058915361214L;
    private static final String MATERIAL = "Material";
    private static final String DESCRIPCION = "Descripción";
    private static final String UN = "UN";
    private static final String MARCA = "Marca";
    private static final String CANTIDAD_PEDIDO = "Cant. Pedido";
    private static final String TOT_FACT = "Tot/Fact.";
    private static final String CANT_PRM = "Cant/Prm";
    private static final String PRECIO_NETO = "Precio Neto";
    private static final String PRECIO_IVA = "Precio + iva";
    private static final String PRECIO_COMP = "Precio Comp.";
    private static final String PRECIO_LISTA = "Precio Lista";
    private static final String DESCUENTO = "% Descuento";
    private static final String TIPO_MATERIAL = "Tipo Mat.";
    private static String columnNames[] = {
        MATERIAL, DESCRIPCION, UN, MARCA, CANTIDAD_PEDIDO, TOT_FACT, CANT_PRM, PRECIO_NETO, PRECIO_IVA, PRECIO_COMP, PRECIO_LISTA, DESCUENTO, TIPO_MATERIAL
    };
    private static final Class<?> columnTypes[] = {
        String.class, String.class, String.class, String.class,
        String.class, String.class, String.class, String.class,
        String.class, String.class, String.class, String.class,
        String.class
    };
    private List<BeanMaterial> data;

    public ModeloTablaConsultaMaterial(List<BeanMaterial> data) {
        this.data = data;
    }

    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        BeanMaterial material = data.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return material.getMaterial();
            case 1:
                return material.getDescripcion();
            case 2:
                return material.getUn();
            case 3:
                return material.getMarca();
            case 4:
                return material.getCantidadPedido();
            case 5:
                return material.getTotFact();
            case 6:
                return material.getCantPRM();
            case 7:
                return material.getPrecioNeto();
            case 8:
                return material.getPrecioIva();
            case 9:
                return material.getPrecioComp();
            case 10:
                return material.getPrecioLista();
            case 11:
                return material.getDescuento();
            case 12:
                return material.getTipoMaterial();
            default:
                return "";
        }
    }

    public void addMaterial(BeanMaterial bean) {
        this.data.add(0, bean);
        fireTableRowsInserted(0, 0);
    }

    public void removeMaterial(int posicion) {
        for (int i = 0; i < data.size(); i++) {
            if (i == posicion) {
                data.remove(i);
                fireTableRowsDeleted(0, 0);
            }
        }
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        return columnTypes[columnIndex];
    }

    @Override
    public String getColumnName(int columnIndex) {
        return columnNames[columnIndex];
    }
}
